package com.iv.durian.cloud.service;

import com.iv.durian.cloud.Lesson;
import com.iv.durian.cloud.dao.LessonDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by zlw on 2018-06-30.
 */

@Slf4j
@Service
public class LessonService {

    @Autowired
    private LessonDao lessonDao;

    public Lesson get(Integer id){
        return lessonDao.get(id,null);
    }

    public Lesson get(String lessonName){
        if (org.springframework.util.StringUtils.isEmpty(lessonName)) {
            log.error("[課程名為空]");
            return null;
        }
        return  lessonDao.get(null, lessonName);
    }


    public int add( Lesson lesson){
        return lessonDao.add(lesson);
    }

    public int updateLessonName(int id,String lessonName){
        if (org.springframework.util.StringUtils.isEmpty(lessonName)) {
            log.error("[課程名為空]");
            return MyReturnCode.PARAM_IS_EMPTY;
        }
        return lessonDao.updateLessonName(id,lessonName);
    }

    public List<Lesson> list(Integer status, int offset, int limit){
        return lessonDao.list(status,offset,limit);
    }

    public int count(Integer status){
        return lessonDao.count(status);
    }

    public void removeLessonById(Integer id){
        lessonDao.delete(id, null);
    }

    public void removeLessonByName(String lessonName){

        lessonDao.delete(null, lessonName);
    }



}
